<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Evaluer extends CI_Controller {
   
	public function __construct() {
		parent::__construct();
		
		// verif connexion
		$this->load->Model('ConnexionModel');
		if (!$this->ConnexionModel->verifconnexion()) {
			redirect('/connexion/', 'refresh');
		}
	}
	
	public function choixFormation()
	{
//		$dbconnect = $this->load->database();   

		$userId = $this->session->userdata('id');
		
		$this->load->Model('ModuleModel');
		$listeModule = $this->ModuleModel->getModuleUtilisateur($userId);
		
		$this->template->set('title', 'Evaluer');
		
		$this->template->load('layout','choixFormation', array(
			'listeFormation' => $listeModule
		));            
	}           
        
	public function evaluer1()
	{
		
		$this->load->Model('EvaluationModel');
		$nbRow = $this->EvaluationModel->getListeQuestion(1);
		if($nbRow>0)
		{
			$this->EvaluationModel->getFormation();
			$this->template->set('title', 'Evaluer');
			
			$this->template->load('layout','Evaluation',$this->EvaluationModel->getData());              
		}
		else
		{
			redirect('/evaluer/evaluer2', 'refresh');
		}
	}

	public function evaluer2()
	{
		
		$this->load->Model('EvaluationModel');
		$nbRow = $this->EvaluationModel->getListeQuestion(2);
		if($nbRow>0)
		{
			$this->EvaluationModel->getFormation();
			$this->template->set('title', 'Evaluer');
			
			$this->template->load('layout','Evaluation',$this->EvaluationModel->getData());    
		}
		else
		{
		   //$this->session->unset_userdata('idmodule');
		  // redirect('/evaluer/validationEvaluation', 'refresh');
			redirect('/evaluer/evaluer3', 'refresh');
		}
	}

	 public function evaluer3()
	{
		 
		$this->load->Model('EvaluationModel');
		$nbRow = $this->EvaluationModel->getListeQuestion(3);
		if($nbRow>0)
		{
			$this->EvaluationModel->getFormation();
			$this->template->set('title', 'Evaluer');
			
			$this->template->load('layout','Evaluation',$this->EvaluationModel->getData());    
		}
		else
		{
			$this->session->unset_userdata('idmodule');
			redirect('/evaluer/validationEvaluation', 'refresh');   
		}
	}

	public function validationEvaluation()
	{
		$this->load->Model('ValidationevaluationModel');
		$this->template->set('title', 'Evaluer');
		
		$this->template->load('layout','Validationevaluation');            
	}

	public function enregistrerQuestion()
	{
		
		$this->load->Model('EvaluationModel');
		$this->EvaluationModel->enregistrerQuestion();
		if ($_POST["typeEval"]==1)
		{
		   $this->session->set_userdata('idmodule',$_POST["idmodule"]);
			redirect('/evaluer/evaluer2', 'refresh');
		}
		else if ($_POST["typeEval"]==2)
		{
			$this->session->set_userdata('idmodule',$_POST["idmodule"]);
			redirect('/evaluer/evaluer3', 'refresh');
		}
		else
		{

		   $this->session->unset_userdata('idmodule');
		   redirect('/evaluer/validationEvaluation', 'refresh');
		}

	}

	public function isModuleQuestionRealise()
	{
		
		$this->load->Model('ModuleModel');
		echo $this->ModuleModel->isModuleQuestionRealise();
	}
}